<template>
  <div>
    <OrganizationDialog v-model="modelValue" type="user" placeholder="请选择出庭律师" />
    <div class="mt-2" v-if="conflictInfo">
      <div class="text-red-600 mb-2 text-sm">{{ modelValue.name }}律师与此开庭时间冲突</div>
      <div class="rounded bg-zinc-100 p-4 text-sm">
        <div>编号：{{ conflictInfo.id }}</div>
        <div>开庭法院：{{ conflictInfo.court_name }}</div>
        <div>法庭：{{ conflictInfo.court_number }}</div>
        <div>审级：{{ conflictInfo.level }}</div>
        <div>开庭时间：{{ conflictInfo.open_datetime }}</div>
        <div>出庭律师：{{ conflictInfo.open_court_user_name }}</div>
      </div>
    </div>
  </div>
</template>

<script setup lang="jsx">
import { lawyerConflict } from '@/api/court'
import OrganizationDialog from '@/components/Organization/OrganizationDialog.vue'
import { ref, watch } from 'vue'
const props = defineProps({
  openDatetime: String,
})
const modelValue = defineModel({
  type: Object,
})

const conflictInfo = ref(null)
const getLawyerConflict = async () => {
  if (!props.openDatetime || !modelValue.value) return
  const { data } = await lawyerConflict({
    open_date: props.openDatetime.split(' ')[0],
    open_court_user_id: modelValue.value.user_id,
  })
  conflictInfo.value = data?.[0]
}
watch(
  () => [props.openDatetime, modelValue.value],
  () => {
    getLawyerConflict()
  }
)

</script>